package com.xinbochuang.machine.common.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.xinbochuang.machine.admin.domain.system.SysDept;
import com.xinbochuang.machine.admin.domain.system.SysMenu;
import lombok.Data;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author 黄晓鹏
 * @date 2020-09-09 22:48
 */
@Data
public class TreeSelect implements Serializable {

    private static final long serialVersionUID = 1L;

    private static final List<Integer> deptDisabledIds = Arrays.asList(2, 3, 5);

    /**
     * 节点ID
     */
    private Integer id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 是否禁用
     */
    private boolean isDisabled;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect() {

    }

    public TreeSelect(SysDept dept) {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        if (deptDisabledIds.contains(dept.getDeptId())) {
            this.isDisabled = true;
        }
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenu menu) {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

}
